
import { contents_query } from "../../db/insert"
import { movie } from "../movie/movie_item";
import { count_equal } from "../../db/insert"
import { config, objContent } from "../contents/config"
import { resolve } from "path";
const _ = require("lodash")


let count = 0;



// 一个完整分页数据的插入 函数封装
async function contents_query_fn({ searchValue, start, end }) {
    let res = await contents_query({ searchValue, start, end });
    _.forEach(res, item => {


        movie(item)
    })

    // fs.writeFileSync("./查询结果.json", JSON.stringify(res), 'utf-8');
}






//获取满足添加的数据

let pamValue = config[1]

//获取满足条件tv_vierces的总条数
async function get_term() {

    let res = await count_equal(pamValue.category);

    return JSON.parse(res)[0]['COUNT(id)']

}


export async function move_insert_all() {

    let res = await get_term();

    for (let i = 0; i < res;) {
        // console.time("循环开开始" + i)
        let start = process.hrtime();
        
       await contents_query_fn(new objContent(pamValue.category, i, i + 50))
    //    console.timeEnd("循环开开始"+i)
    let end :any = process.hrtime(start)
    end = end[0]+'.'+end[1]+'s';
    console.log(end, pamValue.category +'第' + count++ +"次执行");

        i += 50;
    }



}






